import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';
import {PlatformConfig} from './tenant.model';

enum Api {
    page = "/system-service/tenant/pageTenant",
    list = "/system-service/tenant/listAll",
    save = "/system-service/tenant/save",
    edit = "/system-service/tenant/update",
    get = "/system-service/tenant/getTenant",
    // 获取拥有者租户
    getOwnerTenant = "/system-service/tenant/getOwnerTenant",
    // 更新拥有者租户
    updateOwnerTenant = "/system-service/tenant/updateOwnerTenant",
    getConfig = "/system-service/tenant/getConfig",
    delete = "/system-service/tenant/delete",
    deleteBatch = "/system-service/tenant/deleteBatch",
}

/**
 * 查询列表
 * @param params
 */
export const pageTenant = (params) => {
    return defHttp.get({url: Api.page, params});
}

export const listTenant = (params) => {
    return defHttp.get({url: Api.list, params});
}

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdateTenant = (params, isUpdate) => {
    let url = isUpdate ? Api.edit : Api.save;
    return defHttp.post({url: url, params});
}

/**
 * 获取租户配置
 * @param params
 */
export const getPlatformConfig = () => {
    return defHttp.get<PlatformConfig>({url: Api.getConfig});
}

/**
 * 拥有者获取
 */
export const getOwnerTenant = () => {
    return defHttp.get({url: Api.getOwnerTenant});
}

/**
 * 拥有者更新
 */
export const updateOwnerTenant = (params) => {
    return defHttp.post({url: Api.updateOwnerTenant, params});
}

/**
 * 查询详情
 * @param params
 */
export const getTenant = (params) => {
    return defHttp.get({url: Api.get, params});
}

/**
 * 删除
 * @param params
 */
export const deleteTenant = (params,handleSuccess) => {
    return defHttp.delete({url: Api.delete, data: params}, {joinParamsToUrl: true}).then(()=>{
        handleSuccess();
    });
}

/**
 * 批量删除租户
 * @param params
 */
export const batchDeleteTenant = (params, handleSuccess) => {
    Modal.confirm({
        title: '确认删除',
        content: '是否删除选中数据',
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
            return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
                handleSuccess();
            });
        }
    });
}
